home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-ARM / SEMAPHOR.{26 < prev    next >
Text File  |  1999-09-17  |  2KB  |  69 lines

  1. /*
  2.  * linux/include/asm-arm/semaphore.h
  3.  */
  4. #ifndef __ASM_ARM_SEMAPHORE_H
  5. #define __ASM_ARM_SEMAPHORE_H
  6.  
  7. #include <linux/linkage.h>
  8. #include <asm/system.h>
  9. #include <asm/atomic.h>
  10.  
  11. struct semaphore {
  12.     atomic_t count;
  13.     int waking;
  14.     struct wait_queue * wait;
  15. };
  16.  
  17. #define MUTEX ((struct semaphore) { ATOMIC_INIT(1), 0, NULL })
  18. #define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), 0, NULL })
  19.  
  20. asmlinkage void __down_failed (void /* special register calling convention */);
  21. asmlinkage int  __down_interruptible_failed (void /* special register calling convention */);
  22. asmlinkage void __up_wakeup (void /* special register calling convention */);
  23.  
  24. extern void __down(struct semaphore * sem);
  25. extern int  __down_interruptible(struct semaphore * sem);
  26. extern void __up(struct semaphore * sem);
  27.  
  28. #define sema_init(sem, val)    atomic_set(&((sem)->count), (val))
  29.  
  30. /*
  31.  * These two _must_ execute atomically wrt each other.
  32.  *
  33.  * This is trivially done with load_locked/store_cond,
  34.  * but on the x86 we need an external synchronizer.
  35.  * Currently this is just the global interrupt lock,
  36.  * bah. Go for a smaller spinlock some day.
  37.  *
  38.  * (On the other hand this shouldn't be in any critical
  39.  * path, so..)
  40.  */
  41. static inline void wake_one_more(struct semaphore * sem)
  42. {
  43.     unsigned long flags;
  44.  
  45.     save_flags(flags);
  46.     cli();
  47.     sem->waking++;
  48.     restore_flags(flags);
  49. }
  50.  
  51. static inline int waking_non_zero(struct semaphore *sem, struct task_struct *tsk)
  52. {
  53.     unsigned long flags;
  54.     int ret = 0;
  55.  
  56.     save_flags(flags);
  57.     cli();
  58.     if (sem->waking > 0) {
  59.         sem->waking--;
  60.         ret = 1;
  61.     }
  62.     restore_flags(flags);
  63.     return ret;
  64. }
  65.  
  66. #include <asm/proc/semaphore.h>
  67.  
  68. #endif
  69.